<?php


namespace app\unify\controller;


use app\BaseController;
use think\App;
use think\facade\View;
use think\paginator\driver\Bootstrap;
use think\Request;
use app\unify\model\User as UserModel;

class FileLog extends BaseController
{

    /**
     * @Notes 系统日志
     * @Author EdwardCho
     * @Date 2024/1/4
     * @Time 14:44
     * @Interface index
     * @param \think\Request $r
     * @return string
     * @throws \Exception
     */
    public function index(Request $r)
    {
        $page = $r->param('page', 1);
        $pageSize = $r->param('page_size', 10);
        $file = $r->param('file');

        $log = new \app\unify\model\FileLog();
        $files = $log->files();
        $default = $file ?: $files[0]['real'] ?? '';
        $data = $default ? $log->paginate($default, $page, $pageSize) : [];


        if(!empty($data)){
            // 分页信息
            $paginator = Bootstrap::make(
                $data['data'],
                $data['meta']['page_size'],
                $data['meta']['current_page'],
                $data['meta']['total'],
                false,
                [
                    'path' => '',
                    'query' => request()->param(),
                ]
            )->render();
            $assign = compact('files', 'default', 'data', 'paginator');
            View::assign($assign);
        }else{
            echo "<div style='padding:50px'>暂无日志</div>";die();
        }


        return View::fetch();

    }
}